import { ReactComponent as Copy } from '@/assets/images/copy.svg';
import Tools from '@/utils/tools';
import { Tooltip } from 'antd';
import { useState } from 'react';

interface Props {
  clipboardText: string;
  toolTipText: string;
  placement?:
    | 'top'
    | 'bottom'
    | 'left'
    | 'right'
    | 'topLeft'
    | 'topRight'
    | 'bottomLeft'
    | 'bottomRight'
    | 'leftTop'
    | 'leftBottom'
    | 'rightTop'
    | 'rightBottom';
}
export default function Index({
  clipboardText,
  toolTipText,
  placement = 'top',
}: Props) {
  const [open, setOpen] = useState<boolean>(false);

  function copyFunc() {
    Tools.copyText(clipboardText);
    setOpen(true);
  }
  return (
    <Tooltip
      title="已复制"
      destroyTooltipOnHide
      placement={placement}
      open={open}
    >
      <span>
        <a onClick={copyFunc} className={'copy'}>
          <Copy className={'copyIcon'} />
          {toolTipText}
        </a>
      </span>
    </Tooltip>
  );
}
